/*
 * Powered By [ERP]
 * Since 2014 - 2016
 */

package com.erp.cloudfi.org.profitcenter.dao;

import com.erp.cloudfi.org.profitcenter.model.Profitcenter;
import com.erp.cloudfi.org.profitcenter.vo.query.ProfitcenterQuery;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author smn email:shimengnan007@163.com
 * @version 1.0
 * @since 1.0
 */


@Repository
public class ProfitcenterDao {

	@Autowired private SqlSessionFactory sqlSessionFactory;


	public List<Profitcenter> findCentersByGroup(String longnumber){
		return getSqlSessionTemplate().selectList("Profitcenter.findCentersByGroup", longnumber);
	}

	private SqlSession getSqlSessionTemplate() {
		return sqlSessionFactory.openSession();
	}

	public List<Profitcenter> getCentersByCorpId(String corpId,Integer status){
		//修改状态可以选择
		ProfitcenterQuery query=new ProfitcenterQuery();
		query.setStatus(status);
		query.setCorpid(corpId);
		return getSqlSessionTemplate().selectList("Profitcenter.getCentersByCorpId", query);
	}
	public List<String> getCenteridsByCorpId(String corpId){
		return getSqlSessionTemplate().selectList("Profitcenter.getCenteridsByCorpId", corpId);
	}

	public List<Profitcenter> getCentersByCorpidList(List<String> corpidList, Integer status) {
		//修改状态可以选择
		ProfitcenterQuery query=new ProfitcenterQuery();
		query.setStatus(status);
		query.setCorpids(corpidList);
		return getSqlSessionTemplate().selectList("Profitcenter.getCentersByCorpidList", query);
	}
	public List<String> getCenteridsNotCorpId(String corpId){
		return getSqlSessionTemplate().selectList("Profitcenter.getCenteridsNotCorpId", corpId);
	}
    public List<String> getIds(ProfitcenterQuery query) {
	    return getSqlSessionTemplate().selectList("Profitcenter.getIds", null);
	}
    public List<String> getIds2(ProfitcenterQuery query) {
	    return getSqlSessionTemplate().selectList("Profitcenter.getIds2", null);
	}

	public List<Profitcenter> findAllByQuery(ProfitcenterQuery query) {
		return getSqlSessionTemplate().selectList("Profitcenter.findAllByQuery",query);
	}

	public String findIdByNumber(String number){
		return (String) getSqlSessionTemplate().selectOne("Profitcenter.getIdByNumber", number);
	}

}
